import { Body, Controller, Get, Post, Res, Request, HttpException, HttpStatus, Query } from '@nestjs/common';
import { VideoTagService } from './videoTag.service';
import { UserFuncController } from '../user/userFunc.controller';
import { apibefore } from 'src/router';
import { UserService } from '../user/user.service';
import { VideoTag } from './videoTag.entity';

@Controller(apibefore('/video_tag'))
export class VideoTagController  {
  constructor(private readonly service: VideoTagService,
    private readonly userService: UserService
    ) {
    }

  @Post('/create')
  async create(@Body() data: VideoTag, @Request() req) {
    //查询用户的wx_user
    let findUser = await this.userService.findWxUser(req.headers.token)
    if(findUser.error){
      return new HttpException(findUser.error, HttpStatus.INTERNAL_SERVER_ERROR)
    }
    const saveData = new VideoTag()
    saveData.create_time = new Date()
    saveData.tag_id = data.tag_id
    saveData.video_id = data.video_id
    saveData.user_id = req.headers.token
    return await this.service.create(saveData)
  }
  @Get('/findAll_By_Video_Id')
  async findAll_By_Video_Id(@Query() params){
    return await this.service.findAll_By_Video_Id(params.video_id)
  }

  @Post('/remove')
  async remove(@Body() data: VideoTag){
    return await this.service.remove(data.id)
  }

  @Post('/update')
  async update(@Body() data: VideoTag){
    return await this.service.update(data.id, data.tag_id)
  }
}
